package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.hulk.ratel.common.constant.enums.ArchivedFlag;
import com.hulk.ratel.common.constant.enums.AuditedFlag;
import com.hulk.ratel.common.constant.enums.UseFlag;
import com.hulk.ratel.persistence.entity.Txncode;
import com.hulk.ratel.persistence.repository.ITxncodeRepository;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.NonNull;

/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2018/8/31 下午10:40
 * @Version: 1.0.0
 * @Modify by:
 * Class description
 */
@Slf4j
@Component
public class TxnCodeCache {



    @Autowired
    private ITxncodeRepository txncodeRepository;

    /**
     * 交易代码查询
     *
     * @param txnCode
     */

    @Cached( key = "#txnCode + 'TxnCodeCache_findTxnCodeInfo'", cacheType = CacheType.LOCAL ,expire =600 )
    public Txncode findTxnCodeInfo( @NonNull String txnCode) {
        Txncode param = new Txncode();
        param.setTxnCode(txnCode);
        param.setArchivedFlag(ArchivedFlag.N.getValue());
        param.setAuditedFlag(AuditedFlag.Y.getValue());
        param.setUseFlag(UseFlag.Y.getValue());
        Wrapper<Txncode> queryTxnCodeWrapper = new QueryWrapper<>(param);
        return txncodeRepository.getOne(queryTxnCodeWrapper);
    }
}
